package platform.common.dao.impl;

import platform.common.dao.impl.BaseDomainProviderImpl;

public class AbstractTreeNodeDomainProviderImpl extends
		BaseDomainProviderImpl {
	
	public String getAllNode(){
		return "from "+this.getDomainClassName()+" order by leftValue";
	}
	/**
	 * 
	 * <br/>方法描述:获得本节点的孩子节点（即直接下级）
	 * @return
	 */
	public String getFindChildren() {
		return " from " + this.getDomainClassName() + " where treeLevel=:treeLevel and leftValue>:leftValue " +
				"and rightValue<:rightValue and isolatedFlag=:isolatedFlag";
	}

	/**
	 * 
	 * <br/>方法描述:获得本节点的所有子孙节点
	 * @return
	 */
	public String getFindDescendants(){
		return "from " + this.getDomainClassName() + " where leftValue>:leftValue" +
				" and rightValue<:rightValue and isolatedFlag=:isolatedFlag order by leftValue";
	}
	
	/**
	 * 
	 * <br/>方法描述:获得本节点的所有子孙节点
	 * @return
	 */
	public String getFindThisAndDescendants(){
		return "from " + this.getDomainClassName() + " where leftValue>=:leftValue" +
				" and rightValue<=:rightValue and isolatedFlag=:isolatedFlag order by leftValue";
	}
	
	/**
	 * 
	 * <br/>方法描述:获得本节点的所有上级节点
	 * @return
	 */
	public String getFindAncestors(){
		return "from " + this.getDomainClassName() + " where leftValue<=:leftValue" +
				" and rightValue>=:rightValue and isolatedFlag=:isolatedFlag order by leftValue";
	}

	/**
	 * <br/>方法描述:获得本节点的父节点
	 * @return
	 */
	public String getFindParent(){
		return "from " + this.getDomainClassName() + " where treeLevel=:treeLevel and leftValue<:leftValue " +
				"and rightValue>:rightValue and isolatedFlag=:isolatedFlag";
	}
	/**
	 * 
	 * <br/>方法描述:获取同层是否存在相同名称的节点
	 * @return
	 */
	public String getFindSameName(){
		return " from " + this.getDomainClassName() + " where treeLevel=:treeLevel and leftValue>:leftValue and " +
				"rightValue<:rightValue and name=:name and isolatedFlag=:isolatedFlag";
	}
	/**
	 * 
	 * <br/>方法描述:获取同层是否存在相同名称的节点出本身节点以外
	 * @return
	 */
	public String getFindSameNameOutById(){
		return " from " + this.getDomainClassName() + " where treeLevel=:treeLevel and leftValue>:leftValue and " +
				"rightValue<:rightValue and name=:name and id!=:id and isolatedFlag=:isolatedFlag";
	}
	
	/**
	 * 
	 * <br/>方法描述:获取直接下级节点
	 * @return
	 */
	public String getParent(){
		return " from " + this.getDomainClassName() + " where treeLevel=:treeLevel and leftValue>:leftValue " +
				"and rightValue<:rightValue and isolatedFlag=:isolatedFlag";
	}
	

	/**
	 * 
	 * <br/>方法描述:按隔离标志获取数据,按左值排序
	 * @return
	 */
	public String getLoadFullTree(){
		return "from " + this.getDomainClassName() + " o where o.isolatedFlag=? order by o.leftValue ASC";
	}
	/**
	 * 
	 * <br/>方法描述:按隔离标志获取数据(除去某段区域),按左值排序
	 * @return
	 */
	public String getLoadTreeOutByLeftRight(){
		return "from " + this.getDomainClassName() + " o where o.isolatedFlag=:isolatedFlag and o.leftValue<:leftValue or " +
				"o.leftValue>:rightValue order by o.leftValue ASC";
	}
	
	/**
	 * <br/>方法描述:获取对象所有顶级节点
	 * @return
	 */
	public String getLoadTopTree(){
		return " from "+this.getDomainClassName()+" o where o.treeLevel = 0";
	}
	/**
	 * <br/>方法描述:根据左值删除
	 * @return
	 */
	public String getDeleteByLeftRightValue(){
		return " delete from "+this.getDomainClassName()+" where leftValue>=:leftValue and rightValue<=:rightValue " +
				"and isolatedFlag=:isolatedFlag";
	}
	
	/**
	 * 
	 * <br/>方法描述:更新符合条件记录的左值
	 * @return
	 */
	public String getUpateLeftValue(){
		return " update "+this.getDomainClassName()+" set leftValue=leftValue+:changeValue where leftValue>=:leftValue " +
				"and isolatedFlag=:isolatedFlag";
	}
	
	/**
	 * 
	 * <br/>方法描述:更新符合条件记录的右值
	 * @return
	 */
	public String getUpateRightValue(){
		return " update "+this.getDomainClassName()+" set rightValue=rightValue+:changeValue where rightValue>=:rightValue " +
				"and isolatedFlag=:isolatedFlag";
	}
	
	/**
	 * <br/>方法描述:获取顶级是否存在同名的节点
	 * @return
	 */
	public String getSameNameByTopNode(){
		return " from "+this.getDomainClassName()+" o where o.treeLevel = 0 and name=:name";
	}
	
	/**
	 * 
	 * <br/>方法描述:根据隔离标识删除一棵树
	 * @return
	 */
	public String getDeleteByIsolatedFlag(){
		return " delete from "+this.getDomainClassName()+" where isolatedFlag=:isolatedFlag";
	}
	
	/**
	 * 
	 * <br/>方法描述:根据隔离标识删除一棵树
	 * @return
	 */
	public String getSameNameByTopNodeOutId(){
		return " from "+this.getDomainClassName()+" o where o.treeLevel = 0 and name=:name and id!=:id";
	}
	
	/**
	 * 
	 * <br/>方法描述:按隔离标识获取顶级节点
	 * @return
	 */
	public String getTreeNodeByTopIsolatedFlag(){
		return " from "+this.getDomainClassName()+" where treeLevel = 0 and isolatedFlag=:isolatedFlag";
	}
	
	/**
	 * 
	 * <br/>方法描述:获取某节点及其子孙节点
	 * @return
	 */
	public String getCopyNodes(){
		return "from "+this.getDomainClassName()+" where leftValue>=:leftValue and rightValue<=:rightValue and isolatedFlag=:isolatedFlag";
	}


}
